
import { _decorator, Component, Node } from 'cc';
import { QueueFunction } from '../Constructs/QueueFunction';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = FunctionQueue
 * DateTime = Tue Sep 14 2021 19:47:08 GMT+0800 (中国标准时间)
 * Author = Squall
 * FileBasename = FunctionQueue.ts
 * FileBasenameNoExtension = FunctionQueue
 * URL = db://assets/Scripts/Managers/FunctionQueue.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */
 
@ccclass('FunctionQueue')
export class FunctionQueue extends Component {

    private _functionQueue:Array<QueueFunction> = [];

    start () {
        // [3]
    }

    update (deltaTime: number) {
        for(let i=0;i< this._functionQueue.length;i++){
            let func = this._functionQueue[i];
            if(func.update(deltaTime)){
                this._functionQueue.splice(i--,1);
            }
        }
    }

    public addFunction(func:QueueFunction){
        this._functionQueue.push(func)
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */
